package com.block.merge.sdk;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.block.merge.sdk.bridge.BlockCocosBridge;
import com.block.merge.sdk.manager.BlockVideoManger;

public class GameApplication {

    public static GameApplication getInstance() {
        return InstanceHolder.GAME_APPLICATION;
    }

    private static class InstanceHolder {
        private static final GameApplication GAME_APPLICATION = new GameApplication();
    }

    private void registerActivityLifecycleCallbacks(Application app) {

        app.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {

            @Override
            public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {

            }

            @Override
            public void onActivityStarted(@NonNull Activity activity) {

            }

            @Override
            public void onActivityResumed(@NonNull Activity activity) {
                BlockBusiness.onGameActivityResume(activity);
            }

            @Override
            public void onActivityPaused(@NonNull Activity activity) {
                BlockBusiness.onGameActivityPaused(activity);
            }

            @Override
            public void onActivityStopped(@NonNull Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {

            }

            @Override
            public void onActivityDestroyed(@NonNull Activity activity) {
                BlockBusiness.onActivityDestroyed(activity);
            }
        });

    }

    public void onCreate(Activity activity) {
        Log.e("BloMerge", "onCreateonCreate");
        Context mApplication = activity.getApplicationContext();
        registerActivityLifecycleCallbacks((Application) mApplication);
        BlockBusiness.init(mApplication);
        BlockVideoManger.initMediation(mApplication);

        BlockCocosBridge.getInstance().setMainGameActivity(activity);

    }
}
